package demo.sleuth;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@EnableAutoConfiguration
@RestController
public class Backend {

  @RequestMapping("/api") 
  public String printDate() {
    return new Date().toString();
  }

  public static void main(String[] args) {
    SpringApplication.run(Backend.class,
        "--spring.application.name=backend",
        "--server.port=9000"
    );
	  
//	  System.out.println("*******************Begin**************************");
//	  if(args != null) {
//		  for(String arg:args)
//		  System.out.println("**************:"+arg);
//	  }
//	  System.out.println("*******************END*************************");
//	  SpringApplication.run(Backend.class,args);
  }
  
  @Component
  class ArgumentBean {

		@Autowired
		public ArgumentBean(ApplicationArguments args) {
			
			String[] ss = args.getSourceArgs();
			
			System.out.println("*******************Begin2**************************");
			  if(ss != null) {
				  for(String arg:ss)
				  System.out.println("**************:"+arg);
			  }
			  System.out.println("*******************END2*************************");
			  
		}		
	}
  
  @Component
  class CommandLineBean implements CommandLineRunner {

		public void run(String... args) {
			
			System.out.println("*******************Begin3**************************");
			  if(args != null) {
				  for(String arg:args)
				  System.out.println("**************:"+arg);
			  }
			  System.out.println("*******************END3*************************");
			  
		}

	}
  
  @Component
  class AppBean implements ApplicationRunner {

	@Override
	public void run(ApplicationArguments args) throws Exception {

		String[] ss = args.getSourceArgs();
		
		System.out.println("*******************Begin4**************************");
		  if(ss != null) {
			  for(String arg:ss)
			  System.out.println("**************:"+arg);
		  }
		  System.out.println("*******************END4*************************");
		
	} 
  }
  
  @Bean
  public ApplicationRunner getApplicationRunner() {
	  return new ApplicationRunner() {
			@Override
			public void run(ApplicationArguments args) throws Exception {

				String[] ss = args.getSourceArgs();
				
				System.out.println("*******************Begin5**************************");
				  if(ss != null) {
					  for(String arg:ss)
					  System.out.println("**************:"+arg);
				  }
				  System.out.println("*******************END5*************************");
				
			} 		  
	  };
  }
}
